﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

//@author A0085749L
namespace EZXPNS
{
    public partial class PaymentAccountForm : Form
    {
        public PaymentAccountForm()
        {
            InitializeComponent();
        }

        private void PaymentAccountForm_Load(object sender, EventArgs e)
        {
            CreditLabel.Text = Payment.Credit.ToString("c");
            DebitLabel.Text = Payment.Debit.ToString("c");
            CashLabel.Text = Payment.Cash.ToString("c");
            EzlinkLabel.Text = Payment.Ezlink.ToString("c");
            OthersLabel.Text = Payment.Others.ToString("c");
            
            if (Payment.Credit > 0)
                CreditLabel.ForeColor = Color.Green;
            else if(Payment.Credit<0)
                CreditLabel.ForeColor = Color.Red;
            else
                CreditLabel.ForeColor = Color.Black;
            
            if (Payment.Debit > 0)
                DebitLabel.ForeColor = Color.Green;
            else if (Payment.Debit < 0)
                DebitLabel.ForeColor = Color.Red;
            else
                DebitLabel.ForeColor = Color.Black;

            if (Payment.Cash > 0)
                CashLabel.ForeColor = Color.Green;
            else if (Payment.Cash < 0)
                CashLabel.ForeColor = Color.Red;
            else
                CashLabel.ForeColor = Color.Black;

            if (Payment.Ezlink > 0)
                EzlinkLabel.ForeColor = Color.Green;
            else if (Payment.Ezlink < 0)
                EzlinkLabel.ForeColor = Color.Red;
            else
                EzlinkLabel.ForeColor = Color.Black;

            if (Payment.Others > 0)
                OthersLabel.ForeColor = Color.Green;
            else if (Payment.Others < 0)
                OthersLabel.ForeColor = Color.Red;
            else
                OthersLabel.ForeColor = Color.Black;
        }

        private void GoButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (fromComboBox.Text == "")
                {
                    MessageBox.Show("Please select which account you want to transfer from.");
                    return;
                }
                if (toComboBox.Text == "")
                {
                    MessageBox.Show("Please select which account you want to transfer to.");
                    return;
                }
                Payment.transfer(fromComboBox.Text, toComboBox.Text, decimal.Parse(amountTextBox.Text));
                MessageBox.Show("Amount transferred successfully!");
                CreditLabel.Text = Payment.Credit.ToString("c");
                DebitLabel.Text = Payment.Debit.ToString("c");
                CashLabel.Text = Payment.Cash.ToString("c");
                EzlinkLabel.Text = Payment.Ezlink.ToString("c");
                OthersLabel.Text = Payment.Others.ToString("c");

                if (Payment.Credit > 0)
                    CreditLabel.ForeColor = Color.Green;
                else if (Payment.Credit < 0)
                    CreditLabel.ForeColor = Color.Red;
                else
                    CreditLabel.ForeColor = Color.Black;

                if (Payment.Debit > 0)
                    DebitLabel.ForeColor = Color.Green;
                else if (Payment.Debit < 0)
                    DebitLabel.ForeColor = Color.Red;
                else
                    DebitLabel.ForeColor = Color.Black;

                if (Payment.Cash > 0)
                    CashLabel.ForeColor = Color.Green;
                else if (Payment.Cash < 0)
                    CashLabel.ForeColor = Color.Red;
                else
                    CashLabel.ForeColor = Color.Black;

                if (Payment.Ezlink > 0)
                    EzlinkLabel.ForeColor = Color.Green;
                else if (Payment.Ezlink < 0)
                    EzlinkLabel.ForeColor = Color.Red;
                else
                    EzlinkLabel.ForeColor = Color.Black;

                if (Payment.Others > 0)
                    OthersLabel.ForeColor = Color.Green;
                else if (Payment.Others < 0)
                    OthersLabel.ForeColor = Color.Red;
                else
                    OthersLabel.ForeColor = Color.Black;
                
                //Refresh data storage
                Payment.UpdatePayment();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }
}
